package JunitTest;

import java.lang.reflect.Field;

public class StudentTest {
    public static void main(String[] args) {
        Student stu = new Student("小明",16);
        Class<? extends Student> stuClass = stu.getClass();
        Field[] stuClassDeclaredFields = stuClass.getDeclaredFields();
        for (Field stuClassDeclaredField : stuClassDeclaredFields) {
            stuClassDeclaredField.setAccessible(true);
            String name = stuClassDeclaredField.getName();
            Class<?> type = stuClassDeclaredField.getType();
            System.out.println(name + " " + type);
            try {
                Object value = stuClassDeclaredField.get(stu);
                System.out.println(value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}
